﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp
{
#region demo1

    /*
    b1 
    b3 
    b2 
    a1 
    a3 
    a2 
    a4 
    b4 
    b5
    */

    public class BaseClass
    {
        public static MyTest a1 = new MyTest("a1");

        public MyTest a2 = new MyTest("a2");

        static BaseClass()
        {
            MyTest a3 = new MyTest("a3");
        }

        public BaseClass()
        {
            MyTest a4 = new MyTest("a4");
        }

        public virtual void MyFun()
        {
            MyTest a5 = new MyTest("a5");
        }
    }

    public class SonClass : BaseClass
    {
        public static MyTest b1 = new MyTest("b1");

        public MyTest b2 = new MyTest("b2");

        static SonClass()
        {
            MyTest b3 = new MyTest("b3");
        }

        public SonClass()
        {
            MyTest b4 = new MyTest("b4");
        }

        public new void MyFun()
        {
            MyTest b5 = new MyTest("b5");
        }
    }

    public class MyTest
    {
        public MyTest(string info)
        {
            Console.WriteLine(info);
        }
    }

#endregion 

#region demo2

    public class Father
    {
        public virtual void Show()
        {
            Console.WriteLine(this.GetType().ToString());
        }
    }

    public class Sun : Father
    {
        public new virtual void Show()
        {
            Console.WriteLine(this.GetType().ToString());
        }
    }

    public class Children : Father
    {
        public override void Show()
        {
            Console.WriteLine(this.GetType().ToString());
        }
    }

    public class GrandSun : Sun
    {
        public override void Show()
        {
            Console.WriteLine(this.GetType().ToString());
        }
    }

    public class MyTest2
    {
        /// <summary>
        /// 测试继承
        /// </summary>
        public static void Test()
        {
            Father father = new Father();
            father.Show();
            Sun sun = new Sun();
            sun.Show();
            Children children = new Children();
            children.Show();
            GrandSun grandSun = new GrandSun();
            grandSun.Show();

            Console.WriteLine("---------------------------------");

            father = sun as Father;
            father.Show();

            father = children as Father;
            father.Show();

            Console.WriteLine("---------------------------------");
            Console.WriteLine("sun methods:");
            foreach (var method in sun.GetType().GetMethods())
            {
                Console.WriteLine(method.Name);
            }
            Console.WriteLine("children methods:");
            foreach (var method in children.GetType().GetMethods())
            {
                Console.WriteLine(method.Name);
            }
        }
    }

#endregion
}
